//
//  MainViewController.swift
//  sinaweibo
//
//  Created by peter on 15/12/8.
//  Copyright © 2015年 peter. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
  @objc private func commpostClick () {
      print(__FUNCTION__)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        //添加子控制器
       addChildViewControllers()
     //自定义tabbar
    let MaintabBar = MainTabBar()
        
      setValue(MaintabBar, forKey: "tabBar")
        addChildViewControllers()
        //监听按钮的点击事件
        MaintabBar.commoseBtn.addTarget(self, action: "commpostClick", forControlEvents: .TouchUpInside)
    }
    private func addChildViewControllers() {
     addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DIscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", imageName: "tabbar_profile")
   
    }
    
    //使用重载进行封装
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        //封装导航控制器
        self.tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: vc )
        //设置首页
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        
        //添加导航控制器
        addChildViewController(nav)
    }
}
